import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Param,
  Body,
  UsePipes,
  ValidationPipe,
} from '@nestjs/common';
import { MenuService } from '../services/menu.service';
import { Menu } from '../models/menu.entity';

@Controller('menus')
export class MenuController {
  constructor(private readonly menuService: MenuService) {}

  @Get()
  async getMenus(): Promise<Menu[]> {
    return this.menuService.findAll();
  }

  @Get(':id')
  async getMenu(@Param('id') id: string): Promise<Menu | null> {
    return this.menuService.findOne(Number(id));
  }

  @Post()
  @UsePipes(new ValidationPipe())
  async createMenu(@Body() menuData: Partial<Menu>): Promise<Menu> {
    return this.menuService.create(menuData);
  }

  @Put(':id')
  @UsePipes(new ValidationPipe())
  async updateMenu(
    @Param('id') id: string,
    @Body() menuData: Partial<Menu>,
  ): Promise<Menu | null> {
    return this.menuService.update(Number(id), menuData);
  }

  @Delete(':id')
  async deleteMenu(@Param('id') id: string): Promise<Menu | null> {
    return this.menuService.remove(Number(id));
  }
}
